#include <stdio.h>
/* 打印华氏摄氏对应表 */
main()
{
    float fahr, celsius;
    int lower, upper, step;

    // 华氏转摄氏
    lower = 0;
    upper = 300;
    step = 20;
    fahr = lower;

    printf("F to C\n");
    while (fahr <= upper) {
        celsius = (fahr - 32.0) * (5.0 / 9.0);
        printf("%3.0f %6.1f\n", fahr, celsius);
        fahr = fahr + step;
    }


    // 用for循环并逆序打印
    printf("use for loop and reverse order\n");
    for (fahr = 300; fahr >= 0; fahr = fahr - 20) {
        printf("%3.0f %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32));
    }


    // 摄氏转华氏
    lower = 0;
    upper = 300;
    step = 20;
    celsius = lower;

    printf("C to F\n");
    while (celsius <= upper) {
        fahr = celsius * (9.0 / 5.0) + 32;
        printf("%3.0f %6.1f\n", celsius, fahr);
        celsius = celsius + step;
    }

}